package wsi.gui.resolve.model;

import javafx.beans.property.DoubleProperty;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;

import org.rygh.core.xml.XmlLeaf;
import org.rygh.core.xml.XmlObject;
import org.rygh.core.xml.XmlPath;
import org.rygh.semantic.func.RdfPathFunctionalityController;
import org.rygh.semantic.model.ex.PredicatePath;

import wsi.match.XmlFunctionalityController;

public class MatchInfoTuple {

	private final DoubleProperty xpathFunctionality = new SimpleDoubleProperty(
			this, "xpathFunctionality");
	private final StringProperty xpath = new SimpleStringProperty(this, "xpath");
	private final StringProperty valueInXml = new SimpleStringProperty(this,
			"valueInXml");
	private final StringProperty valueInRdf = new SimpleStringProperty(this,
			"valueInRdf");
	private final DoubleProperty predicatePathFunctionality = new SimpleDoubleProperty(
			this, "predicatePathFunctionality");
	private final StringProperty predicatePath = new SimpleStringProperty(this,
			"predicatePath");

	public MatchInfoTuple(XmlLeaf node, XmlFunctionalityController xmlfunc) {
		XmlObject obj = node.getValue();

		String xpath_s = obj.getAttribute("t:xpath");
		XmlPath _xpath = node.getParent().getParent().getXpath()
				.appendRelativePath(xpath_s);
		// System.out.println("_xpath " + _xpath);

		xpathFunctionality.set(xmlfunc.getCompleteInverseFunctionality(_xpath));

		xpath.set(xpath_s);
		valueInXml.set(obj.getAttribute("t:value_in_xml"));
		valueInRdf.set(obj.getAttribute("t:value_in_rdf"));

		String ppath_str = obj.getAttribute("t:predicates");
		predicatePath.set(ppath_str);

		PredicatePath ppath = new PredicatePath(ppath_str);
		double func = ppath.isTemp() ? 0 : RdfPathFunctionalityController
				.shared().getInverseFunctionality(ppath);

		predicatePathFunctionality.set(func);
	}

	public double getPredicatePathFunctionality() {
		return predicatePathFunctionality.get();
	}

	public double getXpathFunctionality() {
		return xpathFunctionality.get();
	}

	public DoubleProperty predicatePathFunctionalityProperty() {
		return predicatePathFunctionality;
	}

	public StringProperty predicatePathProperty() {
		return predicatePath;
	}

	public StringProperty valueInRdfProperty() {
		return valueInRdf;
	}

	public StringProperty valueInXmlProperty() {
		return valueInXml;
	}

	public DoubleProperty xpathFunctionalityProperty() {
		return xpathFunctionality;
	}

	public StringProperty xpathProperty() {
		return xpath;
	}
}
